using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Coffee.SurveyControls.SurveyQuestions
{

    public class SQCheckBoxListOther : SurveyQuestionRow
    {
        public SQCheckBoxListOther(SurveyControl parent, XmlNode configuration)
            : base(parent, configuration)
        {
        }

        public override bool Validate()
        {
            return true;
        }

        public override void LoadData()
        {
            //LoadDynamicData();

            if (Parent.Mapper != null)
            {
                CheckBoxListOther curr = ((CheckBoxListOther)CurrentControl);
                // Cast control and assign to property
                //this.Configuration.SelectNodes("");
                curr.KeyField = "VendorId";
                curr.ItemField = "Name";

                //((Label)PreviousControl).Text = Parent.Mapper.Previous.GetProperty(ctlId);
                curr.LoadData((DataTable)Parent.Mapper.Current.GetProperty(ctlId), "VendorId", "Name");
            }
        }

        public override void SaveData()
        {
            // Cast the current control and retrieve property
            //TextBox tCurr = (TextBox)CurrentControl;

            if (Parent.Mapper != null)
            {
                // apply the value to the assigned field
                //Parent.Mapper.Current.SetProperty(ctlId, tCurr.Text);
            }
        }

        public override void LoadDynamicData()
        {

        }

        protected override void Initialize()
        {

        }

        protected override Control CreateCurrentDataControl()
        {
            // Create controls
            CheckBoxListOther other = new CheckBoxListOther();
            Coffee.Binding.ConfigureBinding(other, rootNode);
            other.DataBind();
            return other;
        }

        protected override Control CreatePreviousDataControl()
        {
            return new Label();
        }
    }
}